package com.zmc.product.infrastructure.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zmc.common.utils.StringUtils;
import com.zmc.product.infrastructure.bean.query.CommodityCategoryQuery;
import org.springframework.stereotype.Service;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zmc.product.infrastructure.dao.CommodityCategoryDao;
import com.zmc.product.infrastructure.entity.CommodityCategoryEntity;
import com.zmc.product.infrastructure.service.CommodityCategoryService;


/**
 * @author zmc
 */
@Service("commodityCategoryService")
public class CommodityCategoryServiceImpl extends ServiceImpl<CommodityCategoryDao, CommodityCategoryEntity> implements CommodityCategoryService {


    @Override
    public List<CommodityCategoryEntity> selectCommodityCategoryList(CommodityCategoryQuery query) {
        LambdaQueryWrapper<CommodityCategoryEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(query.getName()), CommodityCategoryEntity::getName, query.getName())
                .eq(StringUtils.isNotEmpty(query.getDescription()), CommodityCategoryEntity::getDescription, query.getDescription())
                .eq(query.getParentId() != null, CommodityCategoryEntity::getParentId, query.getParentId())
                .orderByAsc(CommodityCategoryEntity::getParentId).orderByAsc(CommodityCategoryEntity::getOrderNum);
        return list(wrapper);
    }
}